package org.sky.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class ReidsUtil {
	private static JedisPool pool;

	private ReidsUtil() {
	};

	public static JedisPool getPool() {
		if (pool == null) {
			synchronized (ReidsUtil.class) {
				if (pool == null) {
					JedisPoolConfig config = new JedisPoolConfig();
					config.setMaxIdle(5);
					config.setTestOnBorrow(true);
					pool = new JedisPool(config, "120.24.54.125", 6379);
				}
			}
		}
		return pool;
	}
	
	public static Jedis getJedis() {
		return getPool().getResource();
	}
	
	public static void returnRedis(Jedis jedis) {
		pool.returnResource(jedis);
	}
	
	public static void setValue(String key,String value){
		getJedis().set(key, value);
	}
	
	public static String getValue(String key){
		return getJedis().get(key);
	}
	
	public static void main(String[] args) {
		ReidsUtil.setValue("wssaidong", "1234");
		System.out.println(ReidsUtil.getValue("wssaidong"));
	}
}
